<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>通知公告</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
    <link href="/wangeditor-5.1.23/style.css" rel="stylesheet">
    <script src="/wangeditor-5.1.23/index.js" charset="utf-8"></script>
    <style>
        body { background-color: #ffffff; }
        #editor—wrapper {
            border: 1px solid #ccc;
            z-index: 100; /* 按需定义 */
        }
        #toolbar-container { border-bottom: 1px solid #ccc; }
        #editor-container { height: 300px; }
    </style>
</head>
<body>
<div class="layuimini-container" id="app">
    <div class="layuimini-main">
        <div class="layui-form ">
            <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;"><legend>下载页面设置</legend></fieldset>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">内容</label>
                <input type="hidden" name="content">
                <div class="layui-input-block">
                    <div id="editor—wrapper">
                        <div id="toolbar-container"><!-- 工具栏 --></div>
                        <div id="editor-container"><!-- 编辑器 --></div>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn" id="submitBtn">确认保存</button>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="/js/common.js?v=5" charset="utf-8"></script>
<script>
    layui.use(['form'], function () {
        var form = layui.form, layer = layui.layer, $ = layui.$;
        new Vue({
            el:"#app",
            data:{
            },
            methods:{
                initWangEditor:function (defaultHtml) {
                    const { createEditor, createToolbar } = window.wangEditor
                    const editorConfig = { // 文档地址: https://www.wangeditor.com/v5/menu-config.html#%E6%9C%8D%E5%8A%A1%E7%AB%AF%E5%9C%B0%E5%9D%80
                        placeholder: '请输入...',
                        onChange(editor) {
                            const html = editor.getHtml()
                            $('[name=content]').val(html)
                        },
                        MENU_CONF:{
                            uploadImage:{
                                server: '/admin/upload/wangEditor',
                                maxFileSize: 10 * 1024 * 1024, // 10M
                            }
                        }
                    }

                    const editor = createEditor({
                        selector: '#editor-container',
                        html: defaultHtml,
                        config: editorConfig,
                        mode: 'default', // 'default' or 'simple'
                    })

                    const toolbarConfig = {}
                    const toolbar = createToolbar({
                        editor,
                        selector: '#toolbar-container',
                        config: toolbarConfig,
                        mode: 'default', // or 'simple'
                    })
                },
                getValByName:function(key){
                    for(var k in this.settings){
                        var row = this.settings[k];
                        if(row.name === key){
                            return row.val
                        }
                    }
                    return null;
                },
            },
            mounted:function(){
                var _this = this;
                $.get('/admin/webManage/settings',{},function(res){
                    _this.settings = res.data;
                    var downloadContent = _this.getValByName("downloadContent")
                    _this.initWangEditor(downloadContent);
                })
                //监听提交
                form.on('submit(saveBtn)', function (data) {
                    var formData = data.field;
                    settingSetVal('downloadContent',formData.content,function(res){
                        if (res.code === 0){
                            layer.msg('保存成功',{icon:1})
                        }
                    });
                    return false;
                });

                form.render();

            },
            updated:function(){
                form.render();
            }
        })
    });
</script>
</body>
</html>